 // 序列化
 function getJsonData(stage) {
     var data = new Object();
     data.childs = []; //scene
     data.wheelZoom = stage.wheelZoom;
     data.frames = stage.frames;

     stage.childs.forEach(function(item) {
         var scene = new Object();
         scene.childs = [];
         scene.alpha = item.alpha;
         scene.backgroundColor = item.backgroundColor;
         scene.visible = item.visible;
         scene.areaSelect = item.areaSelect;
         scene.background = item.background ? item.background.src : null;

         item.childs.forEach(function(item1) {
             if ("node" == item1.elementType) {
                 var node = new Object();
                 node.elementType = item1.elementType;
                 node.text = item1.text;
                 node.x = item1.x;
                 node.y = item1.y;
                 node.rotate = item1.rotate;//节点旋转的角度
                 node.fontColor = item1.fontColor;
                 // node.editAble = item1.editAble;
                 node._id = item1._id;
                 node.image = item1.image.src;//节点图片的路径
                 // node.textPosition = item.textPosition;
                 scene.childs.push(node);
             } else {
                 var link = new Object();
                 link.elementType = item1.elementType;
                 link.text = item1.text;
                 link.nodeA_id = item1.nodeA._id;//连线起始点的id值
                 link.nodeZ_id = item1.nodeZ._id;//连线终止点的id值
                 link.fontColor = item1.fontColor;
                 link.arrowsRadius = item1.arrowsRadius; //箭头
                 link.dashedPattern = item1.dashedPattern; //虚线
                 // link.path = item1.path;
                 link.direction = item1.direction;//折线的方向
                 scene.childs.push(link);
             }
         });
         data.childs.push(scene);
     });

     return JSON.stringify(data);
 }
 // 反序列化
 function createTopoFromJson(jsonStr, canvas) {
     eval("var jsonObj = " + jsonStr);
     // console.log(jsonObj); //object对象
     var stage = new JTopo.Stage(canvas);
     stage.frames = jsonObj.frames;
     stage.wheelZoom = jsonObj.wheelZoom;

     jsonObj.childs.forEach(function(item) { //对stage中的scene遍历赋值
         var scene = new JTopo.Scene(stage);
         for (var a in item) { //对scene中的属性赋值
             if ("childs" == a) { //对scene中的childs遍历赋值
                 item.childs.forEach(function(b) {
                     var c = null;
                     var d = b.elementType; //获取节点或连线的elemenType
                     if ("node" == d) {
                         //创建节点并对其属性赋值
                         c = new JTopo.Node();
                         for (var e in b) {
                             if ("image" == e)
                                 c.setImage(b[e], true);
                             else
                                 c[e] = b[e];
                         }
                     } else {
                         //查找连线的起止节点
                         var nodeA = scene.findElements(function(node) { //查找场景中的对象
                             return node._id == b.nodeA_id;
                         });
                         var nodeZ = scene.findElements(function(node) {
                             return node._id == b.nodeZ_id;
                         });
                         if (nodeA && nodeA.length > 0 && nodeZ && nodeZ.length > 0) { //判断起止节点是否找到
                             switch (d) { //根据连线的不同elementType创建不同的连线
                                 case "foldLink":
                                     c = new JTopo.FoldLink(nodeA[0], nodeZ[0]);
                                     break;
                                 case "flexionalLink":
                                     c = new JTopo.FlexionalLink(nodeA[0], nodeZ[0]);
                                     break;
                                 case "curveLink":
                                     c = new JTopo.CurveLink(nodeA[0], nodeZ[0]);
                                     break;
                                 default:
                                     c = new JTopo.Link(nodeA[0], nodeZ[0]);
                             }
                             for (var e in b) {//对连线的属性赋值
                                 c[e] = b[e];
                             }
                             // c.direction = b.direction;
                             // // console.log(b.path.length);
                             // c.text = b.text;
                             // c.fontColor = b.fontColor;
                             // c.arrowsRadius = b.arrowsRadius; //箭头
                             // c.dashedPattern = b.dashedPattern; //虚线
                         }
                     }
                     scene.add(c);
                 });
             } else {
                 scene[a] = item[a];
             }
         }
     });
     return stage;
 }